var section1 = $(".intro").offset().top,
    section2 = $(".download").offset().top;

var isscrolling = false;

$(".nav ul li a").click(function(){
    $(".nav ul li").removeClass("active");
    $(this).parent().addClass("active");
    var num = $(this).attr("data-link");
    switch (num){
        case "1":
            event.preventDefault();
            $("html,body").animate({scrollTop:0}, "500");
            event.stopPropagation();
            isscrolling = !isscrolling;
            break;
        case "2":
            event.preventDefault();
            $("html,body").animate({scrollTop:section1-40}, "500");
            event.stopPropagation();
            isscrolling = !isscrolling;
            break;
        case "3":
            event.preventDefault();
            $("html,body").animate({scrollTop:section2-80}, "500");
            event.stopPropagation();
            isscrolling = !isscrolling;
            break;
        default:
            break;
    }
    setTimeout(function(){isscrolling = !isscrolling},500);
})

$(window).scroll(function(e){
    var offh = $(window).scrollTop();
    if(0<=offh&&offh<section1&&!isscrolling){
        $(".nav ul li").removeClass("active");
        $(".nav ul li.link_1").addClass("active");
    }else if(section1<=offh&&offh<section1+760&&!isscrolling){
        $(".nav ul li").removeClass("active");
        $(".nav ul li.link_2").addClass("active");
    }else if(section1+760<=offh&&offh<section2+760&&!isscrolling){
        $(".nav ul li").removeClass("active");
        $(".nav ul li.link_3").addClass("active");
    }
})
